/*
 * @(#)SmsUtil.java Jul 16, 2015
 * Copyright 2014 UMPay, Inc. All rights reserved.
 * Use is subject to license terms.
 */ 
package com.jflm.util;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;





/** 
 * @version V1.0
 * @author ouyangping
 * @date Jul 16, 2015
 */
public class SmsUtil {
	
	private static final Logger log = LoggerFactory.getLogger(SmsUtil.class);
	
	public static Map<String,String> sendSms ( String mobileNo , String smsContent)  {
		
		Map<String,String> map = new HashMap<String,String>();
		try {
			smsContent = smsContent+PropertiesUtils.getProperty("mandao.sign");
			String sn = PropertiesUtils.getProperty("THREE_SMS_GATE.SN");
			String pwd = PropertiesUtils.getProperty("THREE_SMS_GATE.PWD");
			Client client = new Client(sn, pwd);
		    String smsFormat = URLEncoder.encode(smsContent, "utf8");
			String result_mdsmssend = client.mdsmssend(mobileNo, smsFormat, "", "", "","");
			log.info("返回结果:" +result_mdsmssend);
			if ( !result_mdsmssend.contains("-") && Long.parseLong(result_mdsmssend.trim()) > 0 )  {
				map.put("retCode","0000");
				map.put("retMsg", "短信发送成功!");
			}  else {
				map.put("retCode",result_mdsmssend);
				map.put("retMsg",PropertiesUtils.getProperty(result_mdsmssend.trim(), result_mdsmssend+"网关系统异常"));
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error("发送短信出现异常",e);
			if  ( e.getMessage().contains("Read timed out") ) {
				map.put("retCode","9998");
				map.put("retMsg","短信网关超时");
			} else {
				map.put("retCode","9999");
				map.put("retMsg","系统异常");
			}
		} 
		return map;
	}
	
	/**
	 * ********************************************
	 * method name   : sendSmsNo 
	 * description   : 不带鑫世界前缀
	 * @return       : Map<String,String>
	 * @param        : @param mobileNo
	 * @param        : @param smsContent
	 * @param        : @return
	 * modified      : lihu ,  2017年4月17日  下午12:10:19
	 * @see          : 
	 * *******************************************
	 */
	public static Map<String,String> sendSmsNo( String mobileNo , String smsContent)  {
		
		Map<String,String> map = new HashMap<String,String>();
		try {
			String sn = PropertiesUtils.getProperty("THREE_SMS_GATE.SN");
			String pwd = PropertiesUtils.getProperty("THREE_SMS_GATE.PWD");
			Client client = new Client(sn, pwd);
			String smsFormat = URLEncoder.encode(smsContent, "utf8");
			String result_mdsmssend = client.mdsmssend(mobileNo, smsFormat, "", "", "","");
			log.info("返回结果:" +result_mdsmssend);
			if ( !result_mdsmssend.contains("-") && Long.parseLong(result_mdsmssend.trim()) > 0 )  {
				map.put("retCode","0000");
				map.put("retMsg", "短信发送成功!");
			}  else {
				map.put("retCode",result_mdsmssend);
				map.put("retMsg",PropertiesUtils.getProperty(result_mdsmssend.trim(), result_mdsmssend+"网关系统异常"));
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error("发送短信出现异常",e);
			if  ( e.getMessage().contains("Read timed out") ) {
				map.put("retCode","9998");
				map.put("retMsg","短信网关超时");
			} else {
				map.put("retCode","9999");
				map.put("retMsg","系统异常");
			}
		} 
		return map;
	}
	
	public static void main (String[] args) {
		// 电信 18101243984 ;  移动手机号： 13811341706  联通：18610821400
		System.out.println(SmsUtil.sendSms("13811341706","会员欧阳平您好，联动测试子商户会员回馈，特赠您测试，券码512893417303，有效期至0723【惠商+】"));
		//String ss = ((DynProps) Context4Spring.getInstance("m_dynattr") ).getProperty("SEQ.PROPERTIES.PATH");
		
		//DynProps d =  (DynProps) Context4Spring.getInstance().getBean("DynProps");
		
		
	}
}
